package com.pope.framework.triage.modular.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.pope.framework.core.reqres.response.ResponseData;
import com.pope.framework.dict.modular.entity.DictAllergic;
import com.pope.framework.dict.modular.entity.DictComingChannel;
import com.pope.framework.dict.modular.entity.DictComingWay;
import com.pope.framework.dict.modular.entity.DictCompare;
import com.pope.framework.dict.modular.entity.DictComplaints;
import com.pope.framework.dict.modular.entity.DictComplaintsD;
import com.pope.framework.dict.modular.entity.DictConsciousState;
import com.pope.framework.dict.modular.entity.DictEscort;
import com.pope.framework.dict.modular.entity.DictExamination;
import com.pope.framework.dict.modular.entity.DictGreenChannel;
import com.pope.framework.dict.modular.entity.DictMedical;
import com.pope.framework.dict.modular.entity.DictNorm;
import com.pope.framework.dict.modular.entity.DictRescueWhere;
import com.pope.framework.dict.modular.entity.DictSicknessGrade;
import com.pope.framework.dict.modular.entity.DictStrength;
import com.pope.framework.dict.modular.entity.DictTriageEpidemic;
import com.pope.framework.dict.modular.entity.DictWhereAbouts;
import com.pope.framework.dict.modular.service.DictAllergicService;
import com.pope.framework.dict.modular.service.DictComingChannelService;
import com.pope.framework.dict.modular.service.DictComingWayService;
import com.pope.framework.dict.modular.service.DictCompareService;
import com.pope.framework.dict.modular.service.DictComplaintsDService;
import com.pope.framework.dict.modular.service.DictComplaintsService;
import com.pope.framework.dict.modular.service.DictConsciousStateService;
import com.pope.framework.dict.modular.service.DictEscortService;
import com.pope.framework.dict.modular.service.DictExaminationService;
import com.pope.framework.dict.modular.service.DictGreenChannelService;
import com.pope.framework.dict.modular.service.DictMedicalService;
import com.pope.framework.dict.modular.service.DictNormService;
import com.pope.framework.dict.modular.service.DictRescueWhereService;
import com.pope.framework.dict.modular.service.DictSicknessGradeService;
import com.pope.framework.dict.modular.service.DictStrengthService;
import com.pope.framework.dict.modular.service.DictTriageEpidemicService;
import com.pope.framework.dict.modular.service.DictWhereAboutsService;
import com.pope.framework.triage.modular.entity.ComingWay;
import com.pope.framework.triage.modular.vo.DictComplaintClassifyVo;
import com.pope.framework.triage.modular.vo.DictGradeVo;
import com.pope.framework.triage.modular.vo.DictVo;
import com.pope.framework.triage.modular.vo.DicvNormVo;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;

@RestController
//@CrossOrigin(allowCredentials="true",maxAge = 3600)
@CrossOrigin
@RequestMapping("${spring.application.app-id}/dict")
@Api(value="相关字典表API",tags= {"相关字典表API"})
public class DictController {
	@Autowired
	private DictMedicalService dictMedicalService;
	
	@Autowired 
	private DictAllergicService dictAllergicService;
	
	@Autowired
	private DictComingWayService dictComingWayService;
	@Autowired
	private DictEscortService dictEscortService;
	@Autowired
	private DictNormService dictNormService;
	
	@Autowired
	private DictGreenChannelService gictGreenChannelService;
	@Autowired
	private DictCompareService dictCompareService;
	@Autowired
	private DictComplaintsService dictComplaintsService;
	@Autowired
	private DictComplaintsDService dictComplaintsDService;
	@Autowired
	private DictStrengthService dictStrengthService;
	@Autowired
	private DictConsciousStateService dictConsciousStateService;
	@Autowired
	private DictWhereAboutsService dictWhereAboutsService;
	@Autowired
	private DictRescueWhereService dictRescueWhereService;
	
	@Autowired
	private DictComingChannelService dictComingChannelService;
	@Autowired
	private DictTriageEpidemicService dictTriageEpidemicService;
	
	@Autowired
	private DictExaminationService dictExaminationService;
	
	@Autowired
	private DictSicknessGradeService dictSicknessGradeService;
	
	
	@ApiOperation(value = "获取病史字典表",notes = "获取病史字典表")
	@GetMapping("medict/list")
	public ResponseData<List<DictVo>> medicalList(){
		
		QueryWrapper<DictMedical> wrapper=new QueryWrapper<>();
		wrapper.orderByAsc("orders");
		List<DictMedical> dicts=dictMedicalService.list(wrapper);
		List<DictVo> dictVos=CollUtil.newArrayList();
		if(CollUtil.isNotEmpty(dicts)) {
			dicts.forEach(dict->{
				DictVo dictVo=new DictVo();
				BeanUtil.copyProperties(dict, dictVo);
				dictVos.add(dictVo);
			});
		}
		return ResponseData.success(dictVos);
	}
	
	@ApiOperation(value = "获取过敏史字典表",notes = "获取过敏史字典表")
	@GetMapping("allergic/list")
	public ResponseData<List<DictVo>> allergicList(){
		
		QueryWrapper<DictAllergic> wrapper=new QueryWrapper<>();
		wrapper.orderByAsc("orders");
		List<DictAllergic> dicts=dictAllergicService.list(wrapper);
		List<DictVo> dictVos=CollUtil.newArrayList();
		if(CollUtil.isNotEmpty(dicts)) {
			dicts.forEach(dict->{
				DictVo dictVo=new DictVo();
				BeanUtil.copyProperties(dict, dictVo);
				dictVos.add(dictVo);
			});
		}
		return ResponseData.success(dictVos);
	}
	
	
	@ApiOperation(value = "获取来院方式字典表",notes = "获取来院方式字典表")
	@GetMapping("comingWay/list")
	public ResponseData<List<DictVo>> comingWayList(){
		
		QueryWrapper<DictComingWay> wrapper=new QueryWrapper<>();
		wrapper.orderByAsc("orders");
		List<DictComingWay> dicts=dictComingWayService.list(wrapper);
		List<DictVo> dictVos=CollUtil.newArrayList();
		if(CollUtil.isNotEmpty(dicts)) {
			dicts.forEach(dict->{
				DictVo dictVo=new DictVo();
				BeanUtil.copyProperties(dict, dictVo);
				dictVos.add(dictVo);
			});
		}
		return ResponseData.success(dictVos);
	}
	
	
	@ApiOperation(value = "获取陪送方式字典表",notes = "获取陪送方式字典表")
	@GetMapping("escort/list")
	public ResponseData<List<DictVo>> escortList(){
		QueryWrapper<DictEscort> wrapper=new QueryWrapper<>();
		wrapper.orderByAsc("orders");
		List<DictEscort> dicts=dictEscortService.list(wrapper);
		List<DictVo> dictVos=CollUtil.newArrayList();
		if(CollUtil.isNotEmpty(dicts)) {
			dicts.forEach(dict->{
				DictVo dictVo=new DictVo();
				BeanUtil.copyProperties(dict, dictVo);
				dictVos.add(dictVo);
			});
		}
		return ResponseData.success(dictVos);
	}
	
	@ApiOperation(value = "获取绿色通道字典表",notes = "获取绿色通道字典表")
	@GetMapping("channel/list")
	public ResponseData<List<DictVo>> channelList(){
		QueryWrapper<DictGreenChannel> wrapper=new QueryWrapper<>();
		wrapper.orderByAsc("orders");
		List<DictGreenChannel> dicts=gictGreenChannelService.list(wrapper);
		List<DictVo> dictVos=CollUtil.newArrayList();
		if(CollUtil.isNotEmpty(dicts)) {
			dicts.forEach(dict->{
				DictVo dictVo=new DictVo();
				BeanUtil.copyProperties(dict, dictVo);
				dictVos.add(dictVo);
			});
		}
		return ResponseData.success(dictVos);
	}
	
	@ApiOperation(value = "获取生命特征指标字典表",notes = "获取生命特征指标字典表")
	@GetMapping("norm/list")
	public ResponseData<List<DicvNormVo>> normList(){
		QueryWrapper<DictNorm> wrapper=new QueryWrapper<>();
		wrapper.orderByAsc("orders");
		List<DictNorm> dicts=dictNormService.list(wrapper);
		List<DicvNormVo> dictVos=CollUtil.newArrayList();
		if(CollUtil.isNotEmpty(dicts)) {
			dicts.forEach(dict->{
				DicvNormVo dictVo=new DicvNormVo();
				BeanUtil.copyProperties(dict, dictVo);
				dictVos.add(dictVo);
			});
		}
		return ResponseData.success(dictVos);
	}
	
	
	@ApiOperation(value = "获取比较公式字典表",notes = "获取比较公式字典表")
	@GetMapping("compare/list")
	public ResponseData<List<DictVo>> compareList(){
		QueryWrapper<DictCompare> wrapper=new QueryWrapper<>();
		wrapper.orderByAsc("orders");
		List<DictCompare> dicts=dictCompareService.list(wrapper);
		List<DictVo> dictVos=CollUtil.newArrayList();
		if(CollUtil.isNotEmpty(dicts)) {
			dicts.forEach(dict->{
				DictVo dictVo=new DictVo();
				BeanUtil.copyProperties(dict, dictVo);
				dictVos.add(dictVo);
			});
		}
		return ResponseData.success(dictVos);
	}
	
	@ApiOperation(value = "获取主诉分类及其子类信息字典表",notes = "获取主诉分类及其子类信息字典表")
	@GetMapping("complaint/list")
	public ResponseData<List<DictComplaintClassifyVo>> complaintList(){
		//主诉分类
		QueryWrapper<DictComplaints> wrapper=new QueryWrapper<>();
		wrapper.orderByAsc("orders");
		List<DictComplaints> dicts=dictComplaintsService.list(wrapper);
		//主诉明细
		
		QueryWrapper<DictComplaintsD> wrapperD=new QueryWrapper<>();
		wrapperD.orderByAsc("orders");
		List<DictComplaintsD> dictsD=dictComplaintsDService.list(wrapperD);
		
		
		List<DictComplaintClassifyVo> dictVos=CollUtil.newArrayList();
		if(CollUtil.isNotEmpty(dicts)) {
			for(DictComplaints dict:dicts) {
				DictComplaintClassifyVo dictComplaintClassifyVo=new DictComplaintClassifyVo();
				BeanUtil.copyProperties(dict, dictComplaintClassifyVo);
				dictVos.add(dictComplaintClassifyVo);
				for(DictComplaintsD dictD:dictsD) {
					if(dictD.getClassifyCode().equals(dict.getCode())) {
						DictVo dictVo=new DictVo();
						BeanUtil.copyProperties(dictD, dictVo);
						if(dictComplaintClassifyVo.getComplaints()==null) {
							dictComplaintClassifyVo.setComplaints(CollUtil.newArrayList());
						}
						dictComplaintClassifyVo.getComplaints().add(dictVo);
					}
				}
			}
		}
		return ResponseData.success(dictVos);
	}
	
	@ApiOperation(value = "获取主诉强度字典表",notes = "获取主诉强度字典表")
	@GetMapping("strenth/list")
	public ResponseData<List<DictVo>> strenthList(){
		
		QueryWrapper<DictStrength> wrapper=new QueryWrapper<>();
		wrapper.orderByAsc("orders");
		List<DictStrength> dicts=dictStrengthService.list(wrapper);
		List<DictVo> dictVos=CollUtil.newArrayList();
		if(CollUtil.isNotEmpty(dicts)) {
			dicts.forEach(dict->{
				DictVo dictVo=new DictVo();
				BeanUtil.copyProperties(dict, dictVo);
				dictVos.add(dictVo);
			});
		}
		return ResponseData.success(dictVos);
	}
	@ApiOperation(value = "获取意识状态字典表",notes = "获取意识状态字典表")
	@GetMapping("conscious/list")
	public ResponseData<List<DictGradeVo>> consciousList(){
		
		QueryWrapper<DictConsciousState> wrapper=new QueryWrapper<>();
		wrapper.orderByAsc("orders");
		List<DictConsciousState> dicts=dictConsciousStateService.list(wrapper);
		List<DictGradeVo> dictVos=CollUtil.newArrayList();
		if(CollUtil.isNotEmpty(dicts)) {
			dicts.forEach(dict->{
				DictGradeVo dictVo=new DictGradeVo();
				BeanUtil.copyProperties(dict, dictVo);
				dictVos.add(dictVo);
			});
		}
		return ResponseData.success(dictVos);
	}
	
	
	@ApiOperation(value = "获取分诊去向字典表",notes = "获取分诊去向字典表")
	@GetMapping("whereAbouts/list")
	public ResponseData<List<DictVo>> whereAboutsList(){
		
		QueryWrapper<DictWhereAbouts> wrapper=new QueryWrapper<>();
		wrapper.orderByAsc("orders");
		List<DictWhereAbouts> dicts=dictWhereAboutsService.list(wrapper);
		List<DictVo> dictVos=CollUtil.newArrayList();
		if(CollUtil.isNotEmpty(dicts)) {
			dicts.forEach(dict->{
				DictVo dictVo=new DictVo();
				BeanUtil.copyProperties(dict, dictVo);
				dictVos.add(dictVo);
			});
		}
		return ResponseData.success(dictVos);
	}
	
	@ApiOperation(value = "获取离抢去向字典表",notes = "获取离抢去向字典表")
	@GetMapping("resuceWhereAbouts/list")
	public ResponseData<List<DictVo>> resuceWhereAboutsList(){
		
		QueryWrapper<DictRescueWhere> wrapper=new QueryWrapper<>();
		wrapper.orderByAsc("orders");
		List<DictRescueWhere> dicts=dictRescueWhereService.list(wrapper);
		List<DictVo> dictVos=CollUtil.newArrayList();
		if(CollUtil.isNotEmpty(dicts)) {
			dicts.forEach(dict->{
				DictVo dictVo=new DictVo();
				BeanUtil.copyProperties(dict, dictVo);
				dictVos.add(dictVo);
			});
		}
		return ResponseData.success(dictVos);
	}
	
	@ApiOperation(value = "获取来院途径字典表",notes = "获取来院途径字典表")
	@GetMapping("comingChannel/list")
	public ResponseData<List<DictVo>> comingChannelList(){
		
		QueryWrapper<DictComingChannel> wrapper=new QueryWrapper<>();
		wrapper.orderByAsc("orders");
		List<DictComingChannel> dicts=dictComingChannelService.list(wrapper);
		List<DictVo> dictVos=CollUtil.newArrayList();
		if(CollUtil.isNotEmpty(dicts)) {
			dicts.forEach(dict->{
				DictVo dictVo=new DictVo();
				BeanUtil.copyProperties(dict, dictVo);
				dictVos.add(dictVo);
			});
		}
		return ResponseData.success(dictVos);
	}
	
	
	@ApiOperation(value = "获取流行病学史字典表",notes = "获取流行病学史字典表")
	@GetMapping("epidemic/list")
	public ResponseData<List<DictVo>> epidemicList(){
		
		QueryWrapper<DictTriageEpidemic> wrapper=new QueryWrapper<>();
		wrapper.orderByAsc("orders");
		List<DictTriageEpidemic> dicts=dictTriageEpidemicService.list(wrapper);
		List<DictVo> dictVos=CollUtil.newArrayList();
		if(CollUtil.isNotEmpty(dicts)) {
			dicts.forEach(dict->{
				DictVo dictVo=new DictVo();
				BeanUtil.copyProperties(dict, dictVo);
				dictVos.add(dictVo);
			});
		}
		return ResponseData.success(dictVos);
	}
	
	@ApiOperation(value = "检测依据字典表",notes = "检测依据字典表")
	@GetMapping("examination/list")
	public ResponseData<List<DictGradeVo>> examinationList(){
		QueryWrapper<DictExamination> wrapper=new QueryWrapper<>();
		wrapper.orderByAsc("orders");
		List<DictExamination> dicts=dictExaminationService.list(wrapper);
		List<DictGradeVo> dictVos=CollUtil.newArrayList();
		if(CollUtil.isNotEmpty(dicts)) {
			dicts.forEach(dict->{
				DictGradeVo dictVo=new DictGradeVo();
				BeanUtil.copyProperties(dict, dictVo);
				dictVos.add(dictVo);
			});
		}
		return ResponseData.success(dictVos);
	}
	
	@ApiOperation(value = "疼痛检测字典表",notes = "疼痛检测字典表")
	@GetMapping("sickness/list")
	public ResponseData<List<DictGradeVo>> sicknessGradeList(){
		QueryWrapper<DictSicknessGrade> wrapper=new QueryWrapper<>();
		wrapper.orderByAsc("orders");
		List<DictSicknessGrade> dicts=dictSicknessGradeService.list(wrapper);
		List<DictGradeVo> dictVos=CollUtil.newArrayList();
		if(CollUtil.isNotEmpty(dicts)) {
			dicts.forEach(dict->{
				DictGradeVo dictVo=new DictGradeVo();
				BeanUtil.copyProperties(dict, dictVo);
				dictVos.add(dictVo);
			});
		}
		return ResponseData.success(dictVos);
	}
}
